﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Microsoft.Reporting.WinForms;
using StoreHouseA.StoreHouseDataSetTableAdapters;

namespace StoreHouseA
{
    public partial class Form8 : Form
    {
        public Form8()
        {
            InitializeComponent();
        }

        private void Form8_Load(object sender, EventArgs e)
        {
            this.reportViewer1.RefreshReport();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int year = int.Parse(comboBox1.Text);
            int month_from = int.Parse(comboBox2.Text);
            int month_to = int.Parse(comboBox3.Text);
            select_storehouseTableAdapter.Fill(
                this.StoreHouseDataSet.select_storehouse, year,
                Math.Min(month_from, month_to),
                Math.Max(month_from, month_to));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] {
                new ReportParameter("year",year.ToString()),
                new ReportParameter("month_from",Math.Min(month_from,month_to).ToString()),
                new ReportParameter("month_to",Math.Max(month_to,month_from).ToString())
            });
            this.reportViewer1.RefreshReport();
        }

        private void reportViewer1_Drillthrough(object sender, Microsoft.Reporting.WinForms.DrillthroughEventArgs e)
        {
            LocalReport r = (LocalReport)e.Report;
            if ("Report20".Equals(e.ReportPath))
            {
                string customer = r.GetParameters()["in_customer"].Values[0];
                int year = int.Parse(r.GetParameters()["in_year"].Values[0]);
                int month_from = int.Parse(r.GetParameters()["in_month_from"].Values[0]);
                int month_to = int.Parse(r.GetParameters()["in_month_to"].Values[0]);
                r.DataSources.Clear();
                r.DataSources.Add(new ReportDataSource("StoreHouseDataSet_select_sellers",
                    new select_sellersTableAdapter().GetData(customer,year,month_from,month_to)));
            }
            else if ("Report23".Equals(e.ReportPath))
            {
                string customer = r.GetParameters()["in_customer"].Values[0];
                int year = int.Parse(r.GetParameters()["in_year"].Values[0]);
                int month_from = int.Parse(r.GetParameters()["in_month_from"].Values[0]);
                int month_to = int.Parse(r.GetParameters()["in_month_to"].Values[0]);
                r.DataSources.Clear();
                r.DataSources.Add(new ReportDataSource("StoreHouseDataSet_select_sellers",
                    new select_sellersTableAdapter().GetData(customer, year, month_from, month_to)));
            }
        }
    }
}
